package com.example.admin.yuejian21.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.admin.yuejian21.Bean.shaitu;
import com.example.admin.yuejian21.R;
import com.example.admin.yuejian21.ViewHolder.ShaituViewHoolder;
import com.example.admin.yuejian21.activity.ShaituDetailActivity;

import java.util.ArrayList;
import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

import static com.example.admin.yuejian21.activity.LoginActivity.username;

/**
 * Created by Admin on 2017/11/1.
 */

public class shaituListAdapter extends RecyclerView.Adapter {
    private List<shaitu> shaituList =new ArrayList<>();

    private Context context;
    private LayoutInflater layoutInflater;
    public  static String picid;
    public shaituListAdapter(Context context, List<shaitu> shaitu){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);

        this.shaituList.addAll(shaitu);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView =
                layoutInflater.inflate(R.layout.item_shaitu,parent,false);

        ShaituViewHoolder holder =
                new ShaituViewHoolder(itemView);

        return holder;

    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ShaituViewHoolder shaituViewHoolder =
                (ShaituViewHoolder) holder;
        final shaitu shaitu= shaituList.get(position);


        String username1=username;

        String time =shaitu.getUpdate_time();
        String title =shaitu.getTitle();





      shaituViewHoolder.usernameView.setText(username);
      shaituViewHoolder.timeView.setText(time);
        shaituViewHoolder.titleView.setText(title);





        if(shaituList.get(position).getThumb0()!=null){
            Picasso
                    .with(context)
                    .load("http://172.24.10.175/workout/Uploads/"+shaituList.get(position).getThumb0())


                    .into(
                           shaituViewHoolder.pic);}
        shaituViewHoolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, ShaituDetailActivity.class);

                intent.putExtra("pic",shaitu);
                picid = shaitu.getId();


                context.startActivity(intent);

            }
        });


    }

    @Override
    public int getItemCount() {
        return shaituList.size();
    }
}
